package com.example.grpc.client.rpc;

import io.grpc.ManagedChannel;
import io.grpc.stub.AbstractStub;

public abstract class AbstractEndpointGrpcClient<T extends AbstractStub<T>> {
    protected final GrpcChannelManager channelManager;
    
    public AbstractEndpointGrpcClient(GrpcChannelManager channelManager) {
        this.channelManager = channelManager;
    }
    
    protected abstract T createStub(ManagedChannel channel);
    
    protected T getStub() {
        ManagedChannel channel = channelManager.getChannel(provideEndpoint());
        return createStub(channel);
    }
    
    protected T getBlockingStub() {
        return getStub(); // 子类实现具体的blocking/async逻辑
    }
    
    protected abstract Endpoint provideEndpoint();
}